using System;
using Com.Modules.StandardModule.Dtos;
using Com.Modules.StandardModule.Entities;

namespace Com.Modules.StandardModule;

internal static class EDHelper
{
    public static ExampleDto ToDto(this ExampleEntity entity){
        ExampleDto dto = new ExampleDto{
            Id = entity.Id,
            Code = entity.Code,
            Name = entity.Name,
            ParentId = entity.ParentId,
            Depth = entity.Depth,
            IsEndNode = entity.IsEndNode,
            IsEnabled = entity.IsEnabled,
            CreateTime = entity.CreateTime,
            CreaterId = entity.CreaterId,
            IsDelete = entity.IsDelete,
            DeleteTime = entity.DeleteTime,
            DeleterId = entity.DeleterId,
        };
        if(entity.Path != null && entity.Path.Length > 0){
            dto.Path = entity.Path.Split(",").Select(int.Parse).ToList();
        }
        return dto;
    }

    public static ExampleEntity ToEntity(this ExampleDto dto){
        ExampleEntity entity = new ExampleEntity{
            Id = dto.Id,
            Code = dto.Code,
            Name = dto.Name,
            ParentId = dto.ParentId,
            Depth = dto.Depth,
            Path = string.Join(",", dto.Path),
            IsEndNode = dto.IsEndNode,
            IsEnabled = dto.IsEnabled,
            CreateTime = dto.CreateTime,
            CreaterId = dto.CreaterId,
            IsDelete = dto.IsDelete,
            DeleteTime = dto.DeleteTime,
            DeleterId = dto.DeleterId,
        };
        return entity;
    }

}
